<template>
  <div class="image-skeleton" :class="{ 'loading': isLoading }">
    <div class="skeleton-content">
      <div class="skeleton-image"></div>
      <div class="skeleton-text">
        <div class="skeleton-title"></div>
        <div class="skeleton-description"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const props = defineProps({
  delay: {
    type: Number,
    default: 0
  }
})

const isLoading = ref(true)

onMounted(() => {
  if (props.delay > 0) {
    setTimeout(() => {
      isLoading.value = false
    }, props.delay)
  } else {
    isLoading.value = false
  }
})
</script>

<style scoped lang="less">
.image-skeleton {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 12px;
  overflow: hidden;
  background: #f0f0f0;
  position: relative;
  
  &.loading {
    .skeleton-content {
      animation: skeleton-loading 1.5s ease-in-out infinite;
    }
  }
  
  .skeleton-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    
    .skeleton-image {
      flex: 1;
      background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
      background-size: 200% 100%;
      animation: skeleton-shimmer 1.5s infinite;
    }
    
    .skeleton-text {
      padding: 12px;
      background: rgba(255, 255, 255, 0.8);
      
      .skeleton-title {
        height: 16px;
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: skeleton-shimmer 1.5s infinite;
        border-radius: 4px;
        margin-bottom: 8px;
        width: 70%;
      }
      
      .skeleton-description {
        height: 12px;
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: skeleton-shimmer 1.5s infinite;
        border-radius: 4px;
        width: 50%;
      }
    }
  }
}

@keyframes skeleton-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes skeleton-loading {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}
</style> 